var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:['直播中','已结束','未开始'],
    no:true,
    list:[],
    shareLoading:false,
    img_src:app.img_src,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var token = wx.getStorageSync('ACCESS_TOKEN');
    if(token){
      this.data.token = token;
      this.data.parmas = e;
      this.getList(e);
    }else {
      app.page.onLoad(this, e);
    }
  },

  getList(p){
    var t = this,list=[],no=true;
    if(p.scene) {
      var scene = p.scene.split('%26')
    }

    app.request({
      url:getApp().api.siteinfo.apiroot+'live/getRoomList',
      data:{
        hosId:app.api.siteinfo.hosId2,
        userId:scene?scene[2]:'',
        shareLiveId:scene?scene[1]:'',
      },
      success:function (e) {
        if(e.result == 0 && e.data.length) list = e.data;
        else no = false;
        t.setData({list,no},wx.stopPullDownRefresh)
      }
    })
  },

  share(e){
    var d = this.data;
    if(d.shareLoading) return;
    d.shareLoading = true;
    wx.showLoading({title:'图片生成中'});
    app.request({
      url:getApp().api.siteinfo.apiroot+'live/shareImg',
      data:{
        shareLiveId:e.target.dataset.id,
        storeId:app.api.siteinfo.acid,
        referee_id:wx.getStorageSync('USER_INFO').id,
      },
      success(e){
        console.log(e)
        wx.previewImage({urls:[e.imgpath]})
        wx.hideLoading()
        d.shareLoading = false;
      }
    })
  },

  //监听用户下拉动作
  onPullDownRefresh: function () {
    this.getList(this.data.parmas)
  },

  //页面上拉触底事件的处理函数
  onReachBottom: function () {},

  // 用户点击右上角分享
  onShareAppMessage: function () {
    let d = this.data.list;
    return {
      title:d[0].room_name,
      path:'/cheng/pages/live-list/live-list?oriToken='+wx.getStorageSync('ACCESS_TOKEN')+'&referee_id='+wx.getStorageSync('USER_INFO').id,
      imageUrl:d[0].share_img
    }
  },
  //分享朋友圈
  onShareTimeline(){}
})